package com.fbinggun.dt.task.conditions;

import com.fbinggun.dt.task.Task;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.enchantment.EnchantItemEvent;

import java.sql.SQLException;

public class EnchantItem extends Conditions{
    int level=0;
    public EnchantItem(String id, ConfigurationSection config, Task task) {
        super(id, config, task);
        this.level=config.getInt("Level",0);
    }

    @EventHandler
    public void enchant(EnchantItemEvent event) throws SQLException, ClassNotFoundException {
        Player player =event.getEnchanter();
        if(player!=null){
            if(isRun(player)){
                if(level>=event.getExpLevelCost()) {
                    addCount(player, 1);
                }
            }
        }
    }
}
